package com.example.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.reggie.entity.SetmealDish;
import com.example.reggie.mapper.SetmealDishMapper;
import com.example.reggie.service.SetmealDishService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class SetmealDishServiceImpl extends ServiceImpl<SetmealDishMapper, SetmealDish> implements SetmealDishService {


    @Override
    public void removeBySetmealId(Long setmealId) {
        //找到所有的套餐菜品
        List<SetmealDish> setmealDishes = this.list(new QueryWrapper<SetmealDish>().eq("setmeal_id", setmealId));
        //删除所有的套餐菜品
        this.removeByIds(setmealDishes.stream().map(SetmealDish::getId).collect(Collectors.toList()));
    }
}
